// (c)2009 Hoang Manh Quang

function md5ToDigit(string)
{
    var digits = new Array();
    digits[0] = 'b5628e1708669baa1d45e9ffb1d4ac49';
    digits[1] = 'a8271524188bed495b6a282457a4c2d5';
    digits[2] = 'bb807bf0f2acf2ba4afcaadb099b8db1';
    digits[3] = '4791bbc11bf36a773fad6f6d3c10ddb0';
    digits[4] = '07cf7fa4b3cb61560eeb0a3053f140e6';
    digits[5] = '69ebed6007413e618f7121b81a39bcd9';
    digits[6] = '01cae2ab76e0194e321e175399ad2df6';
    digits[7] = 'ee7d185e7711fd5b3baec87d9a0a53cf';
    digits[8] = '6b339fd6c21f82508cff0dd99e18e153';
    digits[9] = '23d59489a9bf9be229b4ab77eeb12b56';
    digits[10] = '4af16efa1311e5bc413a56d4c37b2b71';
    
    digit = '';
    string = hex_md5(string);
    for (index = 0; index < 11; index++) {
        if (string == digits[index]) {
            digit = index;
        }
    }
    return digit;
}
function getString(image)
{
    var myCanvas = document.createElement("canvas");
    var myCanvasContext = myCanvas.getContext("2d");
    var imgWidth = image.width;
    var imgHeight = image.height;
    myCanvas.width = imgWidth;
    myCanvas.height = imgHeight;
    myCanvasContext.drawImage(image, 0, 0);
    var imageData;
    var NewString = '';
    var outputString = '';
    var x = 3;
    while (x <= myCanvas.width - 16)
    {
        imageData = myCanvasContext.getImageData(x, 6, 6, 9);
        NewString = imageData.data.join("");
        outputString += md5ToDigit(NewString);
        x += 8;
    }
    return outputString;
}
